#include <string.h>
#include <stdlib.h>
#include "packagebuffer.h"

PackageBuffer::PackageBuffer()
{
    pBuffer = nullptr;
    nMaxLen = 0;
    nPkgLen = 0;
    nCurLen = 0;
}

PackageBuffer::~PackageBuffer()
{
    Destroy();
}

bool PackageBuffer::Initialize(uint16_t nMax)
{
    pBuffer = (uint8_t *)malloc(nMax);

    if (nullptr != pBuffer)
        memset(pBuffer, 0, nMax);

    nMaxLen = nMax;

    return (nullptr != pBuffer);
}

void PackageBuffer::Destroy()
{
    if (nullptr != pBuffer)
    {
        free(pBuffer);
        pBuffer = nullptr;
    }
}

void PackageBuffer::Reset()
{
    nPkgLen = nCurLen = 0;
}
